package com.graduation.controller;

import com.graduation.entity.Business;
import com.graduation.service.FileUpService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/*
 *@Author:君上
 *@Date 2022/3/14 16:19
 *@Content:
 */
@Controller
public class UploadController {

    @Resource
    private FileUpService fileUpService;

    /**
     * 文件上传
     *
     * @param file
     * @param request
     * @return
     */
    @RequestMapping("/upload.do")
    public ModelAndView fileUpload(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        Map<String, String> map = null;
        try {
            map = fileUpService.insertPaper(file, request);
            String filePath = map.get("filePath");
            mv.addObject("filePath",filePath);
            mv.addObject("fileName",map.get("fileName"));
            mv.addObject("id",map.get("shopName"));
            mv.setViewName("goodsAdd");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return mv;
    }
}
